package com.yx.modules.api.controller;

import com.yx.common.utils.R;
import com.yx.modules.api.annotation.AuthIgnore;
import com.yx.modules.api.service.TbTokenService;
import com.yx.modules.api.service.TbUserService;
import com.yx.pay.oauth.AdvancedUtil;
import com.yx.pay.oauth.CommonUtil;
import com.yx.pay.oauth.SNSUserInfo;
import com.yx.pay.wxpay.sdk.WXPay;
import com.yx.pay.wxpay.sdk.WXPayUtil;
import com.yx.pay.wxpay.test.WXPayConfigImpl;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.UUID;

/**
 * 微信token验证
 * 开发者自定的验证口令
 */
@RestController
@RequestMapping("/api/wx")
public class weixinController {
    private Logger logger = LoggerFactory.getLogger(weixinController.class);

    @Autowired
    private TbUserService tbUserService;

    @Autowired
    private TbTokenService tbTokenService;

//    @AuthIgnoreApi
//    @RequestMapping(value = "/checkToken",method = {RequestMethod.POST,RequestMethod.GET})
//    public void check(@RequestBody(required=false) String body, HttpServletRequest request, HttpServletResponse response) throws IOException {
//        request.setCharacterEncoding("UTF-8");
//        boolean isGet = request.getMethod().toLowerCase().equals("get");
//        logger.error("回调事件进入");
//        PrintWriter out;
//        if (isGet) {
//            //验证服务器地址有效性：微信服务器将发送GET请求到填写的服务器地址URL上，GET请求携带四个参数
//            String signature = request.getParameter("signature");
//            String timestamp = request.getParameter("timestamp");
//            String nonce = request.getParameter("nonce");
//            String echostr = request.getParameter("echostr");
//
//            out = response.getWriter();
//            out.print(echostr);
//            out.flush();
//            out.close();
//        } else {
//            String respMessage = "异常消息！";
//            out = response.getWriter();
//            //推送消息给用户
//            try {
//                logger.error("body:" + body);
//                logger.error("request的消息:" + request);
//                // xml请求解析
//                Map<String, String> requestMap = MessageUtil.parseXmlToMap2(body);
//                logger.error("xml的消息:" + requestMap);
//                // 开发者（open_id）
//                String fromUserName = requestMap.get("FromUserName");
//                logger.error("fromUserName:" + fromUserName);
//                // 接收方帐号（收到的OpenID）
//                String toUserName = requestMap.get("ToUserName");
//                logger.error("toUserName:" + toUserName);
//                // 消息类型
//                String msgType = requestMap.get("MsgType");
//                logger.error("msgType:" + msgType);
//                // 消息内容
//                String content = requestMap.get("Content");
//                logger.error("微信扫码返回的消息:" + content);
//
//
//                //被动回复客户消息（文本）
//                if(msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_TEXT)){
//                    StringBuffer str = new StringBuffer();
//                    str.append("<xml>");
//                    str.append("<ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>");
//                    str.append("<FromUserName><![CDATA[" + toUserName + "]]></FromUserName>");
//                    str.append("<CreateTime>" + new Date() + "</CreateTime>");
//                    str.append("<MsgType><![CDATA[" + msgType + "]]></MsgType>");
//                    str.append("<Content><![CDATA[光头娃：：" + "请联系人工客服" + "]]></Content>");
//                    str.append("</xml>");
//                    System.out.println(str.toString());
//                    out.write(str.toString());
//                }
//
//                //被动回复客户消息(img)图片
//                if(msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_IMAGE)){
//                    StringBuffer str = new StringBuffer();
//                    str.append("<xml>");
//                    str.append("<ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>");
//                    str.append("<FromUserName><![CDATA[" + toUserName + "]]></FromUserName>");
//                    str.append("<CreateTime>" + new Date() + "</CreateTime>");
//                    str.append("<MsgType><![CDATA[" + msgType + "]]></MsgType>");
//                    str.append("<Content><![CDATA[光头娃：：" + "请联系人工客服" + "]]></Content>");
//                    str.append("</xml>");
//                    System.out.println(str.toString());
//                    out.write(str.toString());
//                }
//
//                //被动回复客户消息(voice)语音
//                if(msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_VOICE)){
//                    StringBuffer str = new StringBuffer();
//                    str.append("<xml>");
//                    str.append("<ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>");
//                    str.append("<FromUserName><![CDATA[" + toUserName + "]]></FromUserName>");
//                    str.append("<CreateTime>" + new Date() + "</CreateTime>");
//                    str.append("<MsgType><![CDATA[" + msgType + "]]></MsgType>");
//                    str.append("<Content><![CDATA[光头娃：：" + "请联系人工客服" + "]]></Content>");
//                    str.append("</xml>");
//                    System.out.println(str.toString());
//                    out.write(str.toString());
//                }
//
//                //被动回复客户消息(video)视频
//                if(msgType.equals("video")){
//                    StringBuffer str = new StringBuffer();
//                    str.append("<xml>");
//                    str.append("<ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>");
//                    str.append("<FromUserName><![CDATA[" + toUserName + "]]></FromUserName>");
//                    str.append("<CreateTime>" + new Date() + "</CreateTime>");
//                    str.append("<MsgType><![CDATA[" + msgType + "]]></MsgType>");
//                    str.append("<Content><![CDATA[光头娃：：" + "请联系人工客服" + "]]></Content>");
//                    str.append("</xml>");
//                    System.out.println(str.toString());
//                    out.write(str.toString());
//                }
//
//                //被动回复客户消息(news)图文消息
//                if(msgType.equals(MessageUtil.RESP_MESSAGE_TYPE_NEWS)){
//                    StringBuffer str = new StringBuffer();
//                    str.append("<xml>");
//                    str.append("<ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>");
//                    str.append("<FromUserName><![CDATA[" + toUserName + "]]></FromUserName>");
//                    str.append("<CreateTime>" + new Date() + "</CreateTime>");
//                    str.append("<MsgType><![CDATA[" + msgType + "]]></MsgType>");
//                    str.append("<Content><![CDATA[光头娃：：" + "请联系人工客服" + "]]></Content>");
//                    str.append("</xml>");
//                    System.out.println(str.toString());
//                    out.write(str.toString());
//                }
//
//                // 事件推送
//                if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_EVENT)) {
//                    String eventType = requestMap.get("Event");// 事件类型
//                    String accessToken = AdvancedUtil.getWeixinCgiToken("wxde9b9b1d6c4cc2df", "0ea12b593a6e81c756afe3813675c1cb");
//                    // 扫描带参数二维码
//                    logger.error("二维码扫码事件1");
//                    logger.error("fromUserName"+fromUserName);
//                    logger.error("toUserName"+toUserName);
//
//                    //关注公众号事件
//                    if(eventType.equals("subscribe")){
//                        StringBuffer str = new StringBuffer();
//                        str.append("<xml>");
//                        str.append("<ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>");
//                        str.append("<FromUserName><![CDATA[" + toUserName + "]]></FromUserName>");
//                        str.append("<CreateTime>" + new Date() + "</CreateTime>");
//                        str.append("<MsgType><![CDATA[" + msgType + "]]></MsgType>");
//                        str.append("<Content><![CDATA[" + "终于等到你，还好我没放弃！\n" + "欢迎来到光头娃川味休闲美食世界\n" + "从此刻开始，您不仅可以品尝到种类丰富的健康美食，\n" + "还将拥有一次全新的财富机遇。\n" + "衷心祝愿您能在光头娃的个性世界中，发现全新的自己。" + "]]></Content>");
//                        str.append("</xml>");
//                        System.out.println(str.toString());
//                        out.write(str.toString());
//                    }
//
//                    if (eventType.equals(MessageUtil.EVENT_TYPE_SCAN)||eventType.equals("subscribe")) {
//                        // TODO 处理扫描带参数二维码事件
//                        logger.info("扫描带参数二维码事件2:");
//                        String data1 = requestMap.get("EventKey");
//                        logger.error("data1:" + data1);
//                        String data2 = data1.replace("qrscene_", "");
//                        logger.error("data2:" + data2);
//                        int pid = Integer.valueOf(data2);
//                        logger.error("pid:" + pid);
//                        // 获取用户信息
//                        String accessToken2 = AdvancedUtil.getWeixinCgiToken("wxde9b9b1d6c4cc2df", "0ea12b593a6e81c756afe3813675c1cb");
//                        SNSUserInfo snsUserInfo = AdvancedUtil.getWxUserInfo(accessToken2, fromUserName);
//                        TbUser tbUser = tbUserService.queryOpenId(snsUserInfo.getOpenId());
//                        //使用openid判断是否注册
//                        if (tbUser == null) {
//                            //未注册，注册
//                            tbUser = new TbUser();
//                            tbUser.setUuid(UidUtil.getUUID());
//                            tbUser.setProfileimageurl(snsUserInfo.getHeadImgUrl());
//                            tbUser.setNickname(snsUserInfo.getNickname());
//                            tbUser.setSex(snsUserInfo.getSex() == 1 ? true : false);
//                            tbUser.setUsername(snsUserInfo.getNickname());
//                            tbUser.setWxopenid(snsUserInfo.getOpenId());
//                            tbUser.setBalanceCommission(0);
//                            tbUser.setBalance(0);
//                            tbUser.setType(0);
//                            tbUser.setCreateTime(new Date());
//                            tbUser.setEnabled(true);
//                            tbUser.setSaltvalue("gtw");
//                            tbUser.setType(0);
//                            TbDataInfo tbDataInfo = sysDataInfoService.queryObject(1);
//                            tbUser.setWithdrawaltimes(tbDataInfo.getDate());
//                            tbUser.setCharmvalue(0);
//                            tbUser.setEnergyvaluelevel(0);
//                            tbUser.setEnergyvalue(0);
//                            tbUser.setIntegrallevel(0);
//                            tbUser.setAgentinventory(0);
//                            tbUser.setAgentlevel(0);
//                            tbUser.setBalanceCommission(0);
//                            TbUser uu = tbUserService.queryById(Integer.valueOf(pid));
//                            if (uu == null) {
//                                tbUser.setParentid(1);
//                            } else {
//                                if (uu.getType() == 0) {
//                                    tbUser.setParentid(1);
//                                } else {
//                                    tbUser.setParentid(Integer.valueOf(pid));
//                                }
//                            }
//                            if (tbUserService.queryById(tbUser.getParentid()) != null) {
//                                TbUser user1 = tbUserService.queryById(tbUser.getParentid());
//                                if (tbUserService.queryById(user1.getParentid()) != null) {
//                                    TbUser user2 = tbUserService.queryById(user1.getParentid());
//                                    tbUser.setParentid2(user2.getUserId());
//                                    if (tbUserService.queryById(user2.getParentid()) != null) {
//                                        TbUser user3 = tbUserService.queryById(user2.getParentid());
//                                        tbUser.setParentid3(user3.getUserId());
//                                        if (tbUserService.queryById(user3.getParentid()) != null) {
//                                            TbUser user4 = tbUserService.queryById(user3.getParentid());
//                                            tbUser.setParentid4(user4.getUserId());
//                                        }
//                                    }
//                                }
//                            }
//                            tbUser.setProxyid(0);
//                            tbUser.setProxyid2(0);
//                            tbUser.setProxyid3(0);
//                            tbUser.setProxyid4(0);
//                            tbUser.setBalance(0);
//                            tbUser.setProxydividend(0);
//                            tbUser.setProxybalance(0);
//                            tbUser.setMemberdividend(0);
//                            tbUser.setMemberbalance(0);
//                            tbUserService.add(tbUser);
//                            tbTokenService.createToken(tbUser.getUserId());
//                        }
//                        // 订阅
//                        if (eventType.equals(MessageUtil.EVENT_TYPE_SUBSCRIBE)) {
//                            logger.error("订阅关注事件:");
//                            TextMessage text = new TextMessage();
//                            text.setContent("欢迎关注，光头娃");
//                            text.setToUserName(fromUserName);
//                            text.setFromUserName(toUserName);
//                            text.setCreateTime(System.currentTimeMillis() + "");
//                            text.setMsgType(MessageUtil.RESP_MESSAGE_TYPE_TEXT);
//
////                            respMessage = MessageUtil.(text);
//                        }
//                        // TODO 取消订阅后用户再收不到公众号发送的消息，因此不需要回复消息
//                        else if (eventType.equals(MessageUtil.EVENT_TYPE_UNSUBSCRIBE)) {// 取消订阅
//
//                        }
//
//                    }
//                }
//                }
//            catch(Exception e){
//                    e.printStackTrace();
//                }
//                out.print(respMessage);
//                out.flush();
//                out.close();
//            }
//    }
//        response.getWriter().append("Served at: ").append(request.getContextPath());


    /**
     * 获取签名
     *
     * @return
     */
    @AuthIgnore
    @RequestMapping("/getSignature")
    public R getSignature(String url) {
        System.out.println("=======================进入签名获取===============================");
        //1、获取AccessToken
        String accessToken = getAccessToken();

        //2、获取Ticket
        String jsapi_ticket = getTicket(accessToken);

        //3、时间戳和随机字符串
        String noncestr = UUID.randomUUID().toString().replace("-", "").substring(0, 16);//随机字符串
        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);//时间戳

        //5、将参数排序并拼接字符串
        String str = "jsapi_ticket=" + jsapi_ticket + "&noncestr=" + noncestr + "&timestamp=" + timestamp + "&url=" + url;
        System.out.println("=======================未加密签名="+str+"==============================");
        //6、将字符串进行sha1加密
        String signature = SHA1(str);
        HashMap<String, String> map = new HashMap<>();
        map.put("timestamp", timestamp);
        map.put("noncestr", noncestr);
        map.put("signature", signature);

        return R.ok().put("data", map);
    }

    /**
     * 获取wxpay签名
     *
     * @return
     */
    @AuthIgnore
    @RequestMapping("/getwxpaySignature")
    public R doGetSandboxSignKey(String packageid) throws Exception {
        WXPayConfigImpl config = WXPayConfigImpl.getInstance();
        String str = WXPayUtil.generateNonceStr();
        HashMap<String, String> data = new HashMap<String, String>();
        data.put("appid", config.getAppID());
        data.put("mch_id", config.getMchID());
        data.put("nonce_str", str);
        data.put("package", "prepay_id=" + packageid);
        data.put("timeStamp", System.currentTimeMillis() + "");
        String sign = WXPayUtil.generateSignature(data, config.getKey());
        data.put("sign", sign);
        WXPay wxPay = new WXPay(config);
        boolean isok = wxPay.isResponseSignatureValid(data);
        return R.ok().put("data", data);
    }


    public static String getAccessToken() {
        String access_token = "";
        String grant_type = "client_credential";//获取access_token填写client_credential
        String AppId = "wx83e895bd1ea53c4f";//第三方用户唯一凭证
        String secret = "5a681c10ccf1924582bbb2988dd62053  ";//第三方用户唯一凭证密钥，即appsecret
        //这个url链接地址和参数皆不能变
        String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=" + grant_type + "&appid=" + AppId + "&secret=" + secret;

        try {
            URL urlGet = new URL(url);
            HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();
            http.setRequestMethod("GET"); // 必须是get方式请求
            http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            http.setDoOutput(true);
            http.setDoInput(true);
            System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
            System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
            http.connect();
            InputStream is = http.getInputStream();
            int size = is.available();
            byte[] jsonBytes = new byte[size];
            is.read(jsonBytes);
            String message = new String(jsonBytes, "UTF-8");
            JSONObject demoJson = JSONObject.fromObject(message);
            System.out.println("JSON字符串：" + demoJson);
            access_token = demoJson.getString("access_token");
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return access_token;
    }


    public static String getTicket(String access_token) {
        String ticket = null;
        String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + access_token + "&type=jsapi";//这个url链接和参数不能变
        try {
            URL urlGet = new URL(url);
            HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();
            http.setRequestMethod("GET"); // 必须是get方式请求
            http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            http.setDoOutput(true);
            http.setDoInput(true);
            System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
            System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
            http.connect();
            InputStream is = http.getInputStream();
            int size = is.available();
            byte[] jsonBytes = new byte[size];
            is.read(jsonBytes);
            String message = new String(jsonBytes, "UTF-8");
            JSONObject demoJson = JSONObject.fromObject(message);
            System.out.println("JSON字符串：" + demoJson);
            ticket = demoJson.getString("ticket");
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ticket;
    }


    public static String SHA1(String decript) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-1");
            digest.update(decript.getBytes());
            byte messageDigest[] = digest.digest();
            // Create Hex String
            StringBuffer hexString = new StringBuffer();
            // 字节数组转换为 十六进制 数
            for (int i = 0; i < messageDigest.length; i++) {
                String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
                if (shaHex.length() < 2) {
                    hexString.append(0);
                }
                hexString.append(shaHex);
            }
            return hexString.toString();

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }

    public static void main(String[] args) {
        //1、获取AccessToken
        String accessToken = getAccessToken();

        Logger logger = LoggerFactory.getLogger(AdvancedUtil.class);
        SNSUserInfo snsUserInfo = null;
        // 拼接请求地址
        String requestUrl = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN";
        requestUrl = requestUrl.replace("ACCESS_TOKEN", accessToken).replace("OPENID", "oJwCMwgDNYnIwzHtAl03FTp5G32s");
        // 通过网页授权获取用户信息
        JSONObject jsonObject = CommonUtil.httpsRequest(requestUrl, "GET", null);

        if (null != jsonObject) {
            try {
                snsUserInfo = new SNSUserInfo();
                // 用户的标识
                logger.error(jsonObject.getString("openid"));
                snsUserInfo.setOpenId(jsonObject.getString("openid"));
                // 昵称
                logger.error(jsonObject.getString("nickname"));
                snsUserInfo.setNickname(jsonObject.getString("nickname"));
                // 性别（1是男性，2是女性，0是未知）
                logger.error(jsonObject.getString("sex"));
                snsUserInfo.setSex(jsonObject.getInt("sex"));
                // 用户所在国家
                logger.error(jsonObject.getString("country"));
                snsUserInfo.setCountry(jsonObject.getString("country"));
                // 用户所在省份
                logger.error(jsonObject.getString("province"));
                snsUserInfo.setProvince(jsonObject.getString("province"));
                // 用户所在城市
                logger.error(jsonObject.getString("city"));
                snsUserInfo.setCity(jsonObject.getString("city"));
                // 用户头像
                logger.error(jsonObject.getString("headimgurl"));
                snsUserInfo.setHeadImgUrl(jsonObject.getString("headimgurl"));
            } catch (Exception e) {
                snsUserInfo = null;
                int errorCode = jsonObject.getInt("errcode");
                String errorMsg = jsonObject.getString("errmsg");
                logger.error("获取用户信息失败 errcode:{} errmsg:{}", errorCode, errorMsg);
            }
        }
        System.out.print(accessToken);
//
//        String menu = "{\n" + "    \"button\": [\n" + "        {\n" + "            \"name\": \"进入商城\", \n" + "            \"type\": \"view\", \n" + "            \"url\": \"http://www.guangtouboy.com\"\n" + "        }, \n" + "        {\n" + "            \"name\": \"会员中心\", \n" + "            \"sub_button\": [\n" + "                {\n" + "                    \"type\": \"view\", \n" + "                    \"name\": \"个人中心\", \n" + "                    \"url\": \"http://www.guangtouboy.com/#/Mine\"\n" + "                }, \n" + "                {\n" + "                    \"type\": \"view\", \n" + "                    \"name\": \"我的二维码\", \n" + "                    \"url\": \"http://www.guangtouboy.com/#/MyQRCode\"\n" + "                }, \n" + "                {\n" + "                    \"type\": \"view\", \n" + "                    \"name\": \"商业模式\", \n" + "                    \"url\": \"http://mp.weixin.qq.com/s?__biz=MzI5Nzk0MzIxOA==&mid=100000052&idx=1&sn=a31ebc20876e4d2ce09eac9c405e0fab&chksm=6cac28e95bdba1ff51aa49d5ed9bcf900d7f4d46d9c21e3fe795b8f852d825eec9ef451bc516&scene=18#wechat_redirect\"\n" + "                }\n" + "            ]\n" + "        }, \n" + "        {\n" + "            \"name\": \"光头娃\", \n" + "            \"sub_button\": [\n" + "                {\n" + "                    \"type\": \"view\", \n" + "                    \"name\": \"企业简介\", \n" + "                    \"url\": \"http://mp.weixin.qq.com/s?__biz=MzI5Nzk0MzIxOA==&mid=100000025&idx=1&sn=3eefa392f3e68f053ae778f1035e3c29&chksm=6cac28c45bdba1d29bf093696026c27b4858ba6acedd59c158acb2b0af2b8fa504d282ff29d1&scene=18#wechat_redirect\"\n" + "                }, \n" + "                {\n" + "                    \"type\": \"view\", \n" + "                    \"name\": \"加入我们\", \n" + "                    \"url\": \"http://mp.weixin.qq.com/s?__biz=MzI5Nzk0MzIxOA==&mid=100000027&idx=1&sn=a0f64ceb685c0678422920c99db9818e&chksm=6cac28c65bdba1d09f2e65f533356ffd6718e85da1dc63717f19e1099ad97e5288db9c3649fb&scene=18#wechat_redirect\"\n" + "                }, \n" + "                {\n" + "                    \"type\": \"view\", \n" + "                    \"name\": \"光头娃商学院\", \n" + "                    \"url\": \"http://mp.weixin.qq.com/mp/homepage?__biz=MzI5Nzk0MzIxOA==&hid=1&sn=20a4c23da7d036cb3ed30086bffae4ad&scene=18#wechat_redirect\"\n" + "                }, \n" + "                {\n" + "                    \"type\": \"view\", \n" + "                    \"name\": \"产品H5简介\", \n" + "                    \"url\": \"https://g.eqxiu.com/s/JdoVwkEs?from=sqq\"\n" + "                }\n" + "            ]\n" + "        }\n" + "    ]\n" + "}";
//
//        //2、获取Ticket
//        String jsapi_ticket = getTicket(accessToken);
//
//        //3、时间戳和随机字符串
//        String noncestr = UUID.randomUUID().toString().replace("-", "").substring(0, 16);//随机字符串
//        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);//时间戳
//
//        System.out.println("accessToken:" + accessToken + "\njsapi_ticket:" + jsapi_ticket + "\n时间戳：" + timestamp + "\n随机字符串：" + noncestr);
//
//        //4、获取url
//        String url = "http://www.guangtouboy.com/gtw/login.html";
//
//        //5、将参数排序并拼接字符串
//        String str = "jsapi_ticket=" + jsapi_ticket + "&noncestr=" + noncestr + "&timestamp=" + timestamp + "&url=" + url;
//
//        //6、将字符串进行sha1加密
//        String signature = SHA1(str);
//        System.out.println("参数：" + str + "\n签名：" + signature);
    }
}
